home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-03 | 8.5 KB | 338 lines | [TEXT/KAHL] |
- * ***
- * Methods for a class browser
- *
- * Julian Barkway (c) September 1994 All rights reserved.
- *
- * v3.1.0 Initial release
- * v3.1.1 -
- * v3.1.2 - Changed to allow for different actions for double and single clicks.
- * - Increased use of cascades.
- * - Class>>addSubClass:instanceVariableNames: patched to let through embedded
- * digits.
- * v3.1.3 - Dictionary pane no longer gives error if clicked on when empty.
- * v3.1.5 - Browser completely re-designed to reflect improvements in the basic protocol
- * for Pane and SelectListPane. Protocol for DictionaryPane absorbed into SelectListPane.
- *
- * ***
-
- Class BrowserWindow Window browser
-
- Class ClassPane SelectListPane
- Class MethodPane SelectListPane
- Class EditorPane TextPane theClass method compile
-
- Class Browser Object cp mp ep
-
- *
- * addSubClass:... patched so that it doesn't remove numbers embedded in instance
- * variable names. The downside is that it will let through some illegal names, but
- * since the compiler will trap these when they are used it probably isn't too bad a
- * side-effect.
- *
- Methods Class 'creation'
- addSubClass: aSymbol instanceVariableNames: aString | newClass |
- newClass <- Class new; name: aSymbol; superClass: self;
- variables:
- (aString words: [:x | x isAlphaNumeric ]).
- aSymbol assign: newClass.
- classes at: aSymbol put: newClass
- ]
-
- Methods Class 'display'
- editClass
- " Return an addSubClass:instanceVariableNames: message, filled in with
- data from the Class, ready for evaluation "
- | txt |
- txt <- (self superClass) printString , ' addSubClass: #' ,
- self printString, newLine , ' instanceVariableNames: '''.
- (variables notNil) ifTrue: [
- variables do: [ :var | txt <- (txt , (var asString) , ' ') ]
- ].
- txt <- txt , ''''.
- ^ txt.
- ]
-
- *
- * We sub-class Window to allow the 'close' message to be neatly trapped without
- * needing to make Browser a sub-class of Window (which it clearly isn't)
- *
- Methods BrowserWindow 'all'
- openAt: aPosition withSize: aSize
- (title = '') ifTrue: [ " Only false when restoring a saveImage'd window "
- self title: 'Browser ' , (nextBrowserNum asString).
- nextBrowserNum <- nextBrowserNum + 1
- ].
- super openAt: aPosition withSize: aSize
- |
- close | reply |
- (self wantsSave) ifTrue: [
- reply <- smalltalk inquire: ('Save contents of window ', self title, '?').
- (reply isNil) ifTrue: [ "Note: can return nil for Cancel"
- ^ nil
- ].
- reply ifTrue: [
- ((self mainPane) saveContents: 1) ifFalse: [
- ^ nil "User cancelled save operation"
- ]
- ]
- ].
- super close.
- browser close
- |
- browser: aBrowser
- browser <- aBrowser.
- ]
-
- *
- * A selectable list of all classes in the system.
- *
- Methods ClassPane 'all'
- openOn: aClassDictionary in: aWindow withSizeFrom: topLeft to: bottomRight
- super openOn: aClassDictionary in: aWindow withSizeFrom: topLeft to: bottomRight.
- self font: 'geneva'; fontSize: 9; typeFace: 2;
- button1Action: #prepareMethodPane:;
- button1DoubleClick: #selectClass:;
- owner: self;
- setText
- |
- createPopUpMenu
- pMenu <- PopUpMenu new; title: ''; owner: self; create.
- pMenu addItem: 'Browse Class' action: #browseClass;
- addItem: 'Inspect Class' action: #inspectClass;
- addItem: 'Add New Class' action: #addClass;
- addItem: 'Remove Class' action: #removeClass;
- disableItem: 1; disableItem: 4.
- |
- selectClass: aPoint
- self withSelectedItemSend: #showMethodsForClass: to: parent.
- |
- browseClass
- " browse the given class - modified for v3.1.5"
- self withSelectedItemSend: #editClass: to: parent.
- |
- inspectClass
- "Added for v3.1.5"
- self sendToSelectedItem: #inspect
- |
- addClass
- " add a new class "
- parent editNewClass
- |
- removeClass
- " Will remove class from symbols dictionary
- when we can figure out how... It's not just
- a simple matter of invoking removeKey: "
- ^ nil
- |
- prepareMethodPane: aPoint
- pMenu enableItem: 1; enableItem: 2; enableItem: 3.
- "pMenu enableItem: 4." "Class removal disabled for now..."
- parent prepareMethodPane
- ]
-
- *
- * A selectable list of all methods pertaining to a selected class
- *
- Methods MethodPane 'all'
- openOn: aMethodDictionary in: aWindow withSizeFrom: topLeft to: bottomRight
- super openOn: aMethodDictionary in: aWindow withSizeFrom: topLeft to: bottomRight.
- self font: 'geneva'; fontSize: 9; typeFace: 2;
- button1Action: #prepareEditor:;
- button1DoubleClick: #selectMethod:;
- owner: self.
- |
- createPopUpMenu
- pMenu <- PopUpMenu new; title: ''; owner: self; create.
- pMenu addItem: 'Add New Method' action: #addMethod;
- addItem: 'Remove Method' action: #removeMethod;
- disableItem: 1; disableItem: 2.
- |
- prepareEditor: aPoint
- parent cancelEditor.
- pMenu enableItem: 2
- |
- selectMethod: aPoint
- self withSelectedItemSend: #editMethod: to: parent.
- |
- addMethod
- method <- Method new.
- parent addNewMethod.
- |
- removeMethod
- self withSelectedItemSend: #removeMethod: to: self
- |
- removeMethod: m
- | t |
- " Remove given method from currently selected class "
- (m notNil) ifTrue: [
- t <- (smalltalk inquire: 'Remove method ''', (m name), '''?').
- (t isNil) ifTrue: [
- ^ nil
- ].
- t ifTrue: [
- collection removeKey: (m name).
- self setText.
- pMenu disableItem: 2
- ]
- ]
- |
- showMethodsForClass: c
- self collection: (c methods); setText.
- pMenu enableItem: 1; disableItem: 2.
- parent setClass: c
- |
- clearPane
- self clearAllText.
- pMenu disableItem: 1; disableItem: 2.
- parent cancelEditor
- ]
-
- *
- * A pane which allows methods and classes to be viewed, edited and compiled into the system.
- *
- Methods EditorPane 'all'
- openIn: aWindow withSizeFrom: topLeft to: bottomRight
- self boundsFrom: topLeft to: bottomRight;
- owner: self;
- attachTo: aWindow withSizing: (1 @ 1);
- font: 'monaco'; fontSize: 9.
- |
- parent: anObject
- parent <- anObject
- |
- createPopUpMenu
- pMenu <- PopUpMenu new;
- owner: self;
- title: '';
- create.
- pMenu addItem: 'Accept' action: #accept;
- addItem: 'Cancel' action: #cancel;
- disableItem: 1; disableItem: 2.
- compile <- true
- |
- setClass: c
- theClass <- c
- |
- editClass: c
- self clearAllText.
- self print: (c editClass).
- theClass <- c.
- compile <- false.
- pMenu disableItem: 1; enableItem: 2.
- |
- editNewClass
- self clearAllText;
- print: 'superClass addSubClass: #nameOfClass ', newLine,
- ' instanceVariableNames: ''var1 var2'' '.
- compile <- false.
- pMenu enableItem: 1; enableItem: 2.
- |
- editMethod: m
- self print: m text.
- compile <- true.
- method <- m.
- pMenu enableItem: 1; enableItem: 2
- |
- editNewMethod
- self clearAllText;
- print: ' "A comment stating the method''s function"' , newLine;
- print: ' messageSelector: argumentNames " -- argument names optional"', newLine;
- print: ' | temporaries | "-- temporaries optional"', newLine;
- print: ' body of method', newLine.
- compile <- true.
- method <- Method new.
- pMenu enableItem: 1; enableItem: 2.
- |
- accept
- compile ifTrue: [ self compile ]
- ifFalse: [ self doCommand ]
- |
- cancel
- self clearAllText.
- pMenu disableItem: 1; disableItem: 2.
-
- |
- compile
- method text: (self text).
- (method compileWithClass: theClass)
- ifTrue: [
- theClass methods at: method name put: method.
- parent showMethods
- ].
- |
- doCommand
- " accept tw command "
- [ self text execute. parent showClasses ] fork.
- |
- close
- pMenu dispose
- ]
-
- *
- * The actual browser object is just a co-ordinator for the three panes which do
- * the real work.
- *
- Methods Browser 'all'
- open
- | bwin maxW maxH |
- maxW <- (smalltalk getMaxScreenArea) right.
- maxW <- 450 min: (maxW - 70).
- maxH <- (smalltalk getMaxScreenArea) bottom.
- maxH <- 500 min: (maxH - 70).
- bwin <- BrowserWindow new;
- browser: self;
- openAt: (20@60) withSize: (maxW@maxH).
- self makePanes: bwin.
- |
- makePanes: bwin
- | ww wh ph pw |
- ww <- (bwin size) x.
- wh <- (bwin size) y.
- pw <- (ww / 2) truncated.
- ph <- (wh / 5) truncated.
- cp <- ClassPane new;
- openOn: classes in: bwin withSizeFrom: (-1 @ -1) to: (pw @ ph); parent: self.
- mp <- MethodPane new;
- openOn: nil in: bwin withSizeFrom: ((pw - 1) @ -1) to: ((ww + 1) @ ph);
- parent: self.
- ep <- EditorPane new;
- openIn: bwin withSizeFrom: (-1 @ (ph - 1)) to: ((ww + 1) @ (wh + 1));
- parent: self.
- |
- setClass: c
- ep setClass: c
- |
- showClasses
- cp setText
- |
- showMethodsForClass: c
- mp showMethodsForClass: c
- |
- editClass: c
- ep editClass: c
- |
- editNewClass
- ep editNewClass
- |
- showMethods
- mp setText
- |
- prepareMethodPane
- mp clearPane
- |
- editMethod: m
- ep editMethod: m
- |
- addNewMethod
- ep editNewMethod
- |
- cancelEditor
- ep cancel
- |
- close
- " close our window and remove the pop-up menus"
- cp close.
- mp close.
- ep close.
- ]
-